package com.viethp.mt.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.viethp.mt.activities.R;
import com.viethp.mt.objects.OHave;

public class OHaveAdapter extends ArrayAdapter<OHave> {

	private Context context;
	private ArrayList<OHave> ohaves;

	public OHaveAdapter(Context context, int textViewResourceId,
			ArrayList<OHave> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.ohaves = objects;
	}

	public static class ViewHolder {
		protected TextView tv_title;
		protected TextView tv_exp;
		protected TextView tv_count_applicant;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		ViewHolder viewholder;
		if (v == null) {
			viewholder = new ViewHolder();

			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.lv_activities, null);
			viewholder.tv_title = (TextView) v.findViewById(R.id.tv_title);
			viewholder.tv_exp = (TextView) v.findViewById(R.id.tv_exp);
			viewholder.tv_count_applicant = (TextView) v
					.findViewById(R.id.tv_count_applicant);

			v.setTag(viewholder);
		} else {
			viewholder = (ViewHolder) v.getTag();
		}
		final OHave o = ohaves.get(position);
		if (o != null) {
			if (viewholder.tv_title != null) {
				viewholder.tv_title.setText(o.getTitle());
			}
			if (viewholder.tv_exp != null) {
				viewholder.tv_exp.setText(String.valueOf(o.getExp()));
			}
			if (viewholder.tv_count_applicant != null) {
				viewholder.tv_count_applicant.setText(String.valueOf(o
						.getCountActivity()));
			}
		}
		return v;

	}

}
